package com.example.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.AjaxResult;
import com.example.demo.common.TableDataInfo;
import com.example.demo.controller.base.BaseController;
import com.example.demo.domain.model.Book;
import com.example.demo.domain.query.*;
import com.example.demo.mapping.BookMapping;
import com.example.demo.service.IBookService;
import com.example.demo.service.IBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/borrow")
public class BorrowController extends BaseController {
    @Autowired
    private IBorrowService borrowService;
    @GetMapping("/list")
    public AjaxResult list(BorrowDtlQuery borrowDtlQuery){
      return AjaxResult.success(borrowService.dtl(borrowDtlQuery));
    }



    @PostMapping
    public AjaxResult createBorrow(@RequestBody BorrowCreateQuery borrowCreateQuery){
        int insert = borrowService.insert(borrowCreateQuery);
        return toAjax(insert);
    }
    @PutMapping("/{borrowId}")
    public AjaxResult updateBorrowDate(@PathVariable Long borrowId){
       return toAjax(borrowService.updateBorrowDate(borrowId));
    }
    @GetMapping("/return")
    public AjaxResult returnBooK(Long bookId){
        return toAjax(borrowService.returnBooK(bookId));
    }




}
